﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessComponents;
using BusinessComponents.Managers;
using System.Data;


namespace WaterfrontLodge.WebForms
{
    public partial class CustomerView : System.Web.UI.Page
    {
        String username;
        Customer customer = new Customer();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.User.IsInRole("admin"))
            {
                return;
            }

        }

        protected void Search_Click(object sender, EventArgs e)
        {
            username = this.TxtUsername.Text.Trim();

            if (username == "")
            {
                IList<Customer> customers = ManagerFactory.CustomerMgr.GetAllCustomer();
                LblMassage.Text = "";
                GdvCutomer.DataSourceID = null;
                GdvCutomer.DataSource = customers;
                GdvCutomer.DataBind();
               // GdvCutomer.EnableSortingAndPagingCallbacks = true;
            }

            else if (username != "")
            {
                customer = ManagerFactory.CustomerMgr.GetCustomer(username);
                if (customer == null)
                {
                    LblMassage.Text = "No result!";
                    //DataSet ds=new DataSet();
                    //GdvCutomer.DataSourceID = null;
                    //GdvCutomer.DataSource = ds;
                    GdvCutomer.DataSource = null;
                    GdvCutomer.DataBind();
                   // GdvCutomer.EnableSortingAndPagingCallbacks = true;
                }
                else
                {
                    LblMassage.Text = "";
                    IList<Customer> ListCustomer = new List<Customer>();
                    ListCustomer.Add(customer);

                    GdvCutomer.DataSourceID = null;
                    GdvCutomer.DataSource = ListCustomer;
                    GdvCutomer.DataBind();
                    //GdvCutomer.EnableSortingAndPagingCallbacks = true;
                }


            }
        }

        protected void GdvCutomer_SelectedIndexChanged(object sender, EventArgs e)
        {
            string url;
            url = "~/WebForms/Account/CustomerEdit.aspx?id=";
            //int index = GdvCutomer.SelectedIndex;
            string username = GdvCutomer.SelectedRow.Cells[1].Text.ToString();
            url = url + username;
            Response.Redirect(url);
        }

       
       
    }
}